package com.unf.edu.rms.service;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.unf.edu.rms.dao.Faculty;
import com.unf.edu.rms.dao.FacultyResearch;
import com.unf.edu.rms.dao.UserLogin;

@Service
public class FacultyResearchService {
	

	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	@Transactional
	public List<FacultyResearch> getFacultyResearchList()
	{
		Session session = sessionFactory.getCurrentSession();
		String hql = "FROM FacultyResearch";
		Query query = session.createQuery(hql);
		List <FacultyResearch> facultyResearchList = query.list();
		
		for(int i=0;i<facultyResearchList.size();i++)
		{
			FacultyResearch facultyResearch = (FacultyResearch)facultyResearchList.get(i);
			System.out.println("FacultyService.getFacultyList()============="+facultyResearch.getTitle());
			System.out.println("FacultyService.getFacultyList()============="+facultyResearch.getDescription());
			System.out.println("FacultyService.getFacultyList()============="+facultyResearch.getStatus());
		}
		
		return facultyResearchList;
	}
	
	@Transactional
	public void addNewFacultyResearch(FacultyResearch facultyResearch)
	{
		Session session = sessionFactory.getCurrentSession();
		session.save(facultyResearch);
		
	}
	
	@Transactional
	public FacultyResearch getFacultyResearchById(int facultyResearchId)
	{
		Session session = sessionFactory.getCurrentSession();
		String hql = "FROM FacultyResearch where facultyResearchId=:facultyResearchId";
		Query query = session.createQuery(hql);
		query.setInteger("facultyResearchId", facultyResearchId);
		FacultyResearch facultyresearch = (FacultyResearch)query.list().get(0);
		return facultyresearch;
	}
	
	
	@Transactional
	public void updateFacultyResearch(FacultyResearch facultyresearch)
	{
		Session session = sessionFactory.getCurrentSession();
		String hql = "FROM FacultyResearch where facultyresearchId=:facultyResearchId";
		Query query = session.createQuery(hql);
		query.setInteger("facultyResearchId", facultyresearch.getFacultyResearchId());
		session.update(facultyresearch);
	}
}
